#include <iostream>
#include <unistd.h>
#include <signal.h>
void handler(int signum)
{
    std::cout << "收到一个" << signum << "号信号" << std::endl;
    while (true)
    {
        // 不断获取penging表
        sigset_t pending;
        sigpending(&pending);
        for (int i = 31; i >= 1; i--)
        {
            if (sigismember(&pending, i))
                std::cout << 1;
            else
                std::cout << 0;
        }
        std::cout << std::endl;
        sleep(1);
    }
    exit(0);
}
int main()
{
    struct sigaction new_act, old_act;
    new_act.sa_handler = handler;
    new_act.sa_flags = 0;
    sigaction(SIGINT, &new_act, &old_act); // 对二号信号自定义捕捉
    while (true)
    {
        std::cout << "hello world" << "pid:"<<getpid()<<std::endl;
        sleep(1);
    }
    return 0;
}